package com.csmz.mybookreader.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.csmz.mybookreader.R;
import com.csmz.mybookreader.UserBean.BookInfo;

import java.util.List;


public class BookAdapter extends ArrayAdapter<BookInfo> {
    private int resourceId;
    public BookAdapter(@NonNull Context context, int resource, @NonNull List<BookInfo> objects) {
        super(context, resource, objects);
        resourceId=resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        BookInfo bookInfo=getItem(position);
        View view= LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        ImageView bookImage=view.findViewById(R.id.main_book_image);
        TextView bookName=view.findViewById(R.id.main_book_name);
        TextView bookText=view.findViewById(R.id.main_book_text);
        bookImage.setImageResource(bookInfo.getImageId());
        bookName.setText(bookInfo.getName());
        bookText.setText(bookInfo.getText());
        return  view;
    }
}
